<?php

namespace App\Http\Controllers\Api\V1;

use Carbon\Carbon;
use App\Models\Screen;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Api\V1\Resources\ScreenResource;

class ScreensController extends Controller
{
	public function all()
	{
		
		$screens = Screen::query()
			->orderBy("order")
			->get();
		
		return ScreenResource::collection($screens);
	}


	public function index()
	{
		
		$screens = Screen::query()
			->orderBy("order")
			->where('is_home_search',false)
			->get();
		
		return ScreenResource::collection($screens);
	}


	public function city()
	{
		
		$provinceCode = request('province_code');
		
		if(!$provinceCode){

			return [];
		}else{

			$areas = config('areas');
			$prefix = substr($provinceCode, 0,2);

			$regions = [];
			$i = 0;
			foreach ($areas as $k=>$v) {
				if(substr($k, 0,2) == $prefix && $provinceCode != $k){

					if(substr($k, -2) == '00'){
						$regions[$i]['code'] = $k;
						$regions[$i]['name'] = $v;
						$i++;

					}
					
				}

			}
			return $regions;

		}
	}

	
}
 